import VueRouter from "vue-router";
import Vue from 'vue'
Vue.use(VueRouter)

// 电影
import releasePage from '@/pages/films/release-page.vue'
import nowPlaying from '@/pages/films/now-playing'
import commingSoon from '@/pages/films/comming-soon'

// 电影详情页
import detailsPage from '@/pages/films/details-page.vue'

// 选择影院页
import CinemaSelect from '@/pages/films/select-cinema.vue'

// 影院
import Cinema from '@/pages/cinemas/cinema-view.vue'
import CinemaSearch from '@/pages/cinemas/cinema-search.vue'
import  CinemaList from '@/pages/cinemas/cinema-list.vue'

// 影院详情
import  CinemaDetail from '@/pages/cinemas/cinema-details.vue'

// 资讯
import seekAdvice from '@/pages/act/seek-advice.vue'

// 个人中心
import My from '@/pages/my/my-view.vue'
import MyView from '@/pages/my/my-center.vue'
import Order from '@/pages/my/my-order.vue'
import Setting from '@/pages/my/my-setting.vue'
import History from '@/pages/my/my-history.vue'
import Help from '@/pages/my/my-help.vue'
import RedPackage from '@/pages/my/red-package.vue'

// 登录
import Login from '@/pages/login-view.vue'

// 选择城市页面
import FilmCity  from '@/pages/film-city .vue'

// 404页面
import NotFound from '@/pages/not-found.vue'

const routes = [{
    path:'/',
    redirect: '/films'
},{
    path: '/films',
    component: releasePage,
    meta: {showNavbar: true},
    redirect: '/films/nowPlaying',
    children: [{
        path: 'nowPlaying', // 子路由
        component: nowPlaying,
        meta: { showNavbar: true },

    }, {
        path: 'commingSoon',
        component: commingSoon,
        meta: { showNavbar: true }
    }]
}, {
    // 1. 设置路由 /路径/:参数名
    path: '/film/:filmId',
    component:detailsPage
}, {
    path: '/film/:filmId/cinemas',
    component: CinemaSelect,
},{
    path: '/cinemas',
    component: Cinema,
    meta: {showNavbar: true},
    children:[{
        path: '',
        component: CinemaList,
        meta: {showNavbar: true},
    },{
        path: 'search',
        component: CinemaSearch
    }]
}, {
    path: '/cinema/:cinemaId/film',
    component: CinemaDetail
}, {
    path: '/cinema/:cinemaId/film/:filmId/:showDate',
    name: 'cinemaDetail1', // 路由名
    component: CinemaDetail
},{
    path: '/act',
    component: seekAdvice
},{
    path: '/center',
    component: My,
    redirect: '/center/view',
    children: [{
        path: 'view',
        component: MyView,
        meta: {showNavbar: true},
    },{
        path: 'red-packet',
        component: RedPackage
    },{
        path: 'order',
        component: Order
    },{
        path: 'history',
        component: History
    },{
        path: 'help',
        component: Help
    },{
        path: 'setting',
        component: Setting
    }]
},{
    path: '/login',
    component: Login
}, {
    path: '/city',
    component: FilmCity 
},{
    path: '*',
    component: NotFound
}]
const router = new VueRouter({
    routes,
})

const routerPush = VueRouter.prototype.push;
// 修改原型对象中的push方法
VueRouter.prototype.push = function (location) {
    return routerPush.call(this, location).catch(() => {})
};

// 获取原型对象上的replace函数
const routerReplace = VueRouter.prototype.replace;
// 修改原型对象中的push方法
VueRouter.prototype.replace = function (location) {
    return routerReplace.call(this, location).catch(() => {})
}; 

export default router